/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ManagedBeans;

import Entities.Messages;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import sessionBeans.messagingSessionBean;

/**
 *
 * @author xespin
 */
@ManagedBean(name="messaging")
@SessionScoped
public class messagingManagedBean {
    @EJB
    private messagingSessionBean m_eBeanMessaging;
    
    private String message;
    private String receiver;
    private String login;
    private List<Messages> twats;

    /** Creates a new instance of messagingManagedBean */
    public messagingManagedBean() {
        m_eBeanMessaging = new messagingSessionBean();

    }
    
    /**
     * Send single message from user
     * @param login
     * @return 
     */
    public String sendTwat(String login){
        m_eBeanMessaging.sendTwat(this.message, this.receiver, login);
        this.message = "";
        return "main";
    }
    
    /**
     * Gets message for given user
     * @param login
     * @return 
     */
    public List<Messages> getTwats(String login){
        return  m_eBeanMessaging.getTwats(login);
    }
    
    /**
     * Gets replies for a given message for a single user
     * @param receiverId
     * @param messageId
     * @return 
     */
    public List<Messages> getTwatReplies(Long receiverId, Long messageId){
        return m_eBeanMessaging.getReplies(receiverId, messageId);
    }
    
    public String backToMain(){
        return "main";
    }

    /*
     * 
     *  Getters setters Zone
     * 
     */
    
    public void setMessage(String message) {
        this.message = message;
    }

    public String getMessage() {
        return message;
    }

    public void setReceiver(String receiver) {
        this.receiver = receiver;
    }

    public String getReceiver() {
        return receiver;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }
       
}
